/**
 * 
 */
package it.robertobifulco.ias.principalmanager;



/**
 * @author Roberto Bifulco oltremago@gmail.com
 *
 */
public class PrincipalManager {
	
	private PrincipalRepository repository;
	
	
	
	/**
	 * @param repository
	 */
	public PrincipalManager(PrincipalRepository repository) {
		super();
		this.repository = repository;
	}



	public Principal getPrincipal(String identificator, String password) throws ImpossibleToIdentifyPrincipalException{
		
		String truePassword = this.repository.getPrincipalPassword(identificator);
		
		if(password.equals(truePassword)){
			return new Principal(true,this.repository.getPrincipalRole(identificator),identificator);
		}
		else{
			throw new ImpossibleToIdentifyPrincipalException("Incorrect Password");
		}
	}

}
